home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
9-Digit Zip Code Directory
/
9-Digit Zip Code Directory (American Business Information) (ABIZIP-12).ISO
/
z4src.zip
/
Z4CXCP.C
< prev
next >
Wrap
C/C++ Source or Header
|
1995-05-21
|
7KB
|
215 lines
//----------------------------------------------------------------------------
// MODULE DESCRIPTION
//
// Module: z4cxcp.c
// Title: ZIP+4 Engine
// Notice: John M. Weeder
// Copyright (c) 1993. All rights reserved.
// This module contains proprietary information and should be
// treated as confidential.
//
//----------------------------------------------------------------------------
// MAINTENANCE HISTORY
//
// $Workfile$
// $Revision$
// $Author$
// $Date$
// $Log$
//
//----------------------------------------------------------------------------
// MODULE NARRATIVE
//
//
// This module contains the compressor for the POF file.
//
// The code in this module should be written entirely in C.
// Do not use any C++ constructs.
//
// This module is portable to:
// DOS 3.X+
// MS Windows 3.X+
// OS/2 2.X+
// OS/2 2.0 PM
// SCO UNIX.
//
// The following compilers are supported:
// MSC 6.0A
// MSC/C++ 7.0
// Borland C++ 3.1 for DOS
// Borland C++ 1.0 for OS/2 2.X
// SCO UNIX cc
//
//----------------------------------------------------------------------------
#include <z4.h>
//----------------------------------------------------------------------------
// Prototypes
//----------------------------------------------------------------------------
static BOOL FN_L Z4CXCompressAppend(PDATACOMP, PZ4_CX);
//----------------------------------------------------------------------------
// Description: Compression function
// Parameters: pdatacomp Compressor data
// Returns: Compression function result code. See data.h.
//----------------------------------------------------------------------------
SHORT FN_E Z4CXCompress(PDATACOMP pdatacomp)
{
static BOOL fPending; // ZIP5 record pending?
static Z4_CX cx; // ZIP5 record
static SIZET cMaxZips;
static SIZET cMaxPofs;
static SIZET cPofCities;
static CHAR szZip5[MAX_ZIP5+1];
static SIZET cZip;
static SIZET cState;
static SIZET cCity;
static SIZET cLLName;
static SIZET cFacility;
static SIZET cPof;
LONG lRec = pdatacomp->dlmrec.lId;
PPSZ ppsz = pdatacomp->dlmrec.apsz;
SIZET i;
Z4_STATE state;
CHAR szCity[MAX_CITY+1];
switch (lRec)
{
case DAI_INITIALIZE: // Initialize at startup
cMaxZips = 0;
cMaxPofs = 0;
cPofCities = 0;
Assert(MAX_CITY_ZIP5 <= pdatacomp->cbMax / MAX_ZIP5_BCD);
cZip = DataField(pdatacomp->dlmrec.pcfg, "zipcode");
cPof = DataField(pdatacomp->dlmrec.pcfg, "finance");
cState = DataField(pdatacomp->dlmrec.pcfg, "state_abbrev");
cCity = DataField(pdatacomp->dlmrec.pcfg, "city_name");
cLLName = DataField(pdatacomp->dlmrec.pcfg, "last_line_name");
cFacility = DataField(pdatacomp->dlmrec.pcfg, "facility");
case DAI_START_BLK: // Start block
fPending = FALSE;
return DAO_SUCCESS;
case DAI_TERMINATE: // Terminate
Output("\nMaximum of %u ZIPs in a city/state.\n", cMaxZips);
Output("Maximum of %u POFs in a city/state.\n", cMaxPofs);
Output("%u city/states with > 1 POF.\n", cPofCities);
case DAI_FAILURE:
case DAI_END_BLK: // End block
return DAO_SUCCESS;
case DAI_LAST_REC:
if (!fPending)
return DAO_FAILURE;
if (cx.cFinance > 1)
cPofCities++;
Z4CXCompressAppend(pdatacomp, &cx);
return DAO_FLUSH;
}
if (pdatacomp->dlmrec.fSkipped)
return DAO_SKIP;
// Get state code
state = Z4FindState(ppsz[cState]);
Assert(state != Z4_ST_INVALID);
strcpy(szCity, Z4Clean(ppsz[cCity]));
if (fPending)
{
if (state != cx.state
|| strcmp(cx.szCity, szCity) != 0)
{
if (cx.cFinance > 1)
cPofCities++;
Z4CXCompressAppend(pdatacomp, &cx);
fPending = FALSE;
return DAO_MARK_FLUSH;
}
if (strcmp(szZip5, ppsz[cZip]) != 0)
{
Assert(cx.cZip5 < MAX_CITY_ZIP5);
strcpy(szZip5, ppsz[cZip]);
stra2b(cx.abZip5[cx.cZip5], MAX_ZIP5_BCD, ppsz[cZip], MAX_ZIP5);
cx.cZip5++;
cMaxZips = MAX(cMaxZips, cx.cZip5);
}
for (i = 0; i < cx.cFinance; ++i)
{
CHAR szFinance[MAX_FINANCE+1];
strb2a(cx.abFinance[i], MAX_FINANCE_BCD, szFinance, MAX_FINANCE, TRUE);
szFinance[MAX_FINANCE] = '\0';
if (strcmp(szFinance, ppsz[cPof]) == 0)
break;
}
if (i >= cx.cFinance)
{
Assert(cx.cFinance < MAX_POF_CITY);
stra2b(cx.abFinance[cx.cFinance], MAX_FINANCE_BCD, ppsz[cPof], MAX_FINANCE);
cx.cFinance++;
cMaxPofs = MAX(cMaxPofs, cx.cFinance);
}
return DAO_NEXT;
}
fPending = TRUE;
memset(&cx, 0, sizeof(cx));
cx.state = state;
strcpy(cx.szCity, szCity);
if (ppsz[cFacility][0] == '9')
strcpy(cx.szPO, Z4Clean(ppsz[cLLName]));
stra2b(cx.abFinance[cx.cFinance], MAX_FINANCE_BCD, ppsz[cPof], MAX_FINANCE);
cx.cFinance++;
strcpy(szZip5, ppsz[cZip]);
stra2b(cx.abZip5[cx.cZip5], MAX_ZIP5_BCD, ppsz[cZip], MAX_ZIP5);
cx.cZip5++;
cMaxZips = MAX(cMaxZips, cx.cZip5);
cMaxPofs = MAX(cMaxPofs, cx.cFinance);
return DAO_NEXT;
}
//----------------------------------------------------------------------------
// Description: Compress the current ZIP5 record
// Parameters: pdatacomp Compresser data
// pcx POF record
// Returns: TRUE if successful.
//----------------------------------------------------------------------------
static BOOL FN_L Z4CXCompressAppend(PDATACOMP pdatacomp, PZ4_CX pcx)
{
PBYTE pb = pdatacomp->pb;
SIZET cb, cLen;
*pb = (BYTE)pcx->state; // Store state
pb++;
cLen = strlen(pcx->szCity); // Store city name
memcpy(pb, pcx->szCity, cLen + 1);
pb += cLen + 1;
cLen = strlen(pcx->szPO); // Store post office name
memcpy(pb, pcx->szPO, cLen + 1);
pb += cLen + 1;
// Store POF count
*(PUSHORT)pb = (USHORT)pcx->cFinance;
pb += sizeof(USHORT);
// Store POFs
cb = MAX_FINANCE_BCD * pcx->cFinance;
memcpy(pb, pcx->abFinance, cb);
pb += cb;
*(PUSHORT)pb = (USHORT)pcx->cZip5; // Store ZIP count
pb += sizeof(USHORT);
cb = MAX_ZIP5_BCD * pcx->cZip5; // Store ZIPs
memcpy(pb, pcx->abZip5, cb);
pb += cb;
// Update number of bytes written
pdatacomp->cb = (SIZET)(pb - pdatacomp->pb);
return TRUE;
}
//----------------------------------------------------------------------------
//------------------------------- End of File --------------------------------
//----------------------------------------------------------------------------